package com.jiang.myfm.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.jiang.myfm.MainActivity;
import com.jiang.myfm.R;
import com.jiang.myfm.entities.advertisement.AdvertisementEntity;
import com.jiang.myfm.interfaces.AdvertisementListener;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class AdvertisementActivity extends AppCompatActivity implements Callback<AdvertisementEntity> {
    private ImageView mImageView;
    private AdvertisementListener mAdvertisementListener;
    private String url="http://fdfs.xmcdn.com/group23/M07/A0/E6/wKgJL1hJMEyhUZoXAAGJC2dnp2Q096.jpg";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_advertisement);
        mImageView= (ImageView) findViewById(R.id.advertisement_image);
        mAdvertisementListener=new Retrofit.Builder()
                .baseUrl("http://fdfs.xmcdn.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(AdvertisementListener.class);
        mAdvertisementListener.getImage().enqueue(this);
        Picasso.with(AdvertisementActivity.this).load(url).into(mImageView);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Intent intent=new Intent(AdvertisementActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }).start();
    }

    @Override
    public void onResponse(Call<AdvertisementEntity> call, Response<AdvertisementEntity> response) {

    }

    @Override
    public void onFailure(Call<AdvertisementEntity> call, Throwable t) {

    }
}
